package com.ruoyi.project.module.shao;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.HeEventFlow;
import com.ruoyi.project.service.IHeEventFlowService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;

/**
 * 事件流程Controller
 * 
 * @author ruoyi
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/shao/flow")
public class ShaoFlowController extends BaseController
{
    @Autowired
    private IHeEventFlowService heEventFlowService;

    /**
     * 查询事件流程列表
     */
//    @RequiresPermissions("project:flow:list")
    @GetMapping("/list")
    public TableDataInfo list(HeEventFlow heEventFlow)
    {
        List<HeEventFlow> list = heEventFlowService.selectHeEventFlowList(heEventFlow);
        return getDataTable(list);
    }

    /**
     * 导出事件流程列表
     */
//    @RequiresPermissions("project:flow:export")
    @Log(title = "事件流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeEventFlow heEventFlow)
    {
        List<HeEventFlow> list = heEventFlowService.selectHeEventFlowList(heEventFlow);
        ExcelUtil<HeEventFlow> util = new ExcelUtil<HeEventFlow>(HeEventFlow.class);
        util.exportExcel(response, list, "事件流程数据");
    }

    /**
     * 获取事件流程详细信息
     */
//    @RequiresPermissions("project:flow:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(heEventFlowService.selectHeEventFlowById(id));
    }

    /**
     * 新增事件流程
     */
//    @RequiresPermissions("project:flow:add")
    @Log(title = "事件流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeEventFlow heEventFlow)
    {
        String context=heEventFlow.getProcessStreamContent();
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        heEventFlow.setProcessOperatorName(sysUser.getNickName());
        heEventFlow.setProcessOperatorId(sysUser.getUserId());
        heEventFlow.setProcessStreamContent(sysUser.getNickName()+"补录事件内容："+context);
        heEventFlow.setCreationTime(DateUtils.getNowDate());
        return toAjax(heEventFlowService.insertHeEventFlow(heEventFlow));
    }

    /**
     * 修改事件流程
     */
//    @RequiresPermissions("project:flow:edit")
    @Log(title = "事件流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeEventFlow heEventFlow)
    {
        return toAjax(heEventFlowService.updateHeEventFlow(heEventFlow));
    }

    /**
     * 删除事件流程
     */
//    @RequiresPermissions("project:flow:remove")
    @Log(title = "事件流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(heEventFlowService.deleteHeEventFlowByIds(ids));
    }
}
